
import util from "/common/js/util.js";

var app = getApp();
const pageSize = 15;

Page({
  data: {
    dataList:[],
    scrollTop: 0,
    toView: "",
    showLoadMoreTxt: "over",
    page: 1,
    pageSize: pageSize,
    dataList: [],
    totalResult: pageSize,
    totalnum: 0,
    userId:"",
    userName:""
  },
  onLoad(e) {
    this.searchFn();
    this.setData({
      userId: app.prototype.$userId,
      userName: app.prototype.$userName
    })
    console.log(e);
  },
  
  // onShareAppMessage() {

  //   return {
  //     title: '恒丽书城',
  //     desc: '恒丽书城',
  //     path: 'pages/home/home',
  //   };
  // },
  onScrollToLower() {
    //console.log("---开始触底");
    this.tableList()
  },
  onPullDownRefresh() {
    // 页面被下拉
    console.log("---页面被下拉");
   // dd.stopPullDownRefresh();
   this.searchFn();
  },
  scroll(e) {
    this.setData({
      scrollTop: e.detail.scrollTop,
      toView: ""
    })
  },
  searchFn() {
    this.setData({
      page: 1,
      totalnum: 0,
      dataList: []
    });
    this.tableList()
  },
  tableList(obj){
    let api = "/user/book/integralList";
    let list = {
      page: this.data.page,
      pageSize: this.data.pageSize,
      
    };
    
    //console.log("--list:",list);
    let that = this;
    this.setData({
      showLoadMoreTxt: "load"
    });
    
    // console.log(this.data.totalnum,this.data.totalResult);
    //debugger
    if (this.data.dataList.length >= this.data.totalResult&&this.data.totalResult!=0) {
      this.setData({
        showLoadMoreTxt: "over"
      })
      dd.stopPullDownRefresh();
      return false;
    }
    dd.showLoading({
        content: '数据加载中...',
      })
    let dataList=this.data.dataList;
    app.$post(api, list).then(res => {
      dd.stopPullDownRefresh()
     dd.hideLoading();
      if (res.code == 200) {

        let arr_list=dataList.concat(res.data.list);
        let page=this.data.page;
        page=page+1;
        
        this.setData({
          totalResult: res.data.totalResult,
          page,
          dataList: arr_list,
          showLoadMoreTxt: "over"
        });
        
      }else{
        util.message(res.message);

      }
    })
  },
  onTapFabClick(e) {
    this.setData({
      scrollTop: 0,
      toView: "top"
    })
  },
  gotoNoteAll(){
    let query={};
    query.bookId=this.data.book_info.bookId;
    query.bookName=this.data.book_info.bookName;
    query.userName=app.prototype.$userName;
    query.userId=app.prototype.$userId;
    query.queryType="all";
    let p = Qs.stringify(query);
    let path = '/pages/note/noteGroup/noteGroup';
  // console.log("---p:",p);
    let url = `${path}?${p}`;
    dd.navigateTo({
      url: url
    })
  }
});
